package com.wanhe.shoppingcart.counter;

import com.wanhe.base.model.base.Dish;
import com.wanhe.base.model.base.SallOutDish;
import com.wanhe.base.model.holder.DishHolder;
import com.wanhe.base.model.holder.SallOutHolder;
import com.wanhe.base.util.ObjectUtil;
import com.wanhe.shoppingcart.bean.CartItem;
import com.wanhe.shoppingcart.manager.ICartItem;

/**
 * Created by XieZaiWei on 2017/5/9.
 * 普通菜的加减
 */

public class BaseCounter implements ICounter {
	public static final String COUNTER_TYPE = "base";

	@Override
	public String getCounterType() {
		return COUNTER_TYPE;
	}

	@Override
	public void plus(String dishUuid, boolean isNeedSyncToServer) {
		Dish dish = DishHolder.getInstance().get(dishUuid);
		if (ObjectUtil.checkObject(dish)) {
			CartItem item = new CartItem();
			item.setDish(dish);
			item.setCount(1);
			plus(item, isNeedSyncToServer);
		}
	}

	@Override
	public void plus(ICartItem item, boolean isNeedSyncToServer) {
//		boolean sallOut = item.isSellOut();
//		if (!sallOut) {
//			CartManager.getInstance().addItem(item, isNeedSyncToServer);
//		}else {
//			Toast.makeText(BaseApplication.context, "仅剩的" + item.getName() + "都被你加完啦~", Toast.LENGTH_SHORT).show();
//		}
	}

	@Override
	public void reduce(String foodID, boolean isNeedSyncToServer) {
//		CartManager.getInstance().reduceItemCount(foodID, isNeedSyncToServer);
	}


	@Override
	public void reduce(ICartItem item, boolean isNeedSyncToServer) {
//		CartManager.getInstance().reduceItemCount(item, isNeedSyncToServer);
	}

	/**
	 * 购物车操作部分检测估清
	 *
	 * @author 陈德基
	 * create at 2017/1/19 10:46
	 */
	public boolean isSallOut(Dish dish, int count) {
		boolean isSallOut = false;
		SallOutDish sallOutDish = SallOutHolder.getInstance().get(dish.getCh_dishno());
		if (ObjectUtil.checkObject(sallOutDish)) {
			if (count >= sallOutDish.getWarnNum()) {
				isSallOut = true;
			} else {
				isSallOut = false;
			}
		}
		return isSallOut;
	}

	@Override
	public boolean isCountFilled() {
		return true;
	}
}
